package top.roadvast.aop.aspect;

import org.aspectj.lang.ProceedingJoinPoint;

/**
 * 增强类
 * 通过xml方式增强
 */
public class MyAspect {

    public void before(){
        System.out.println("权限校验");
    }

    public void after(){
        System.out.println("日志记录");
        System.out.println("效率检测");
    }

    public void throwing(){
        System.out.println("抛出异常");
    }

    public void finally00(){
        System.out.println("释放资源");
    }


    //环绕增强
    public Object around(ProceedingJoinPoint joinPoint){
        Object proceed = null;
        try {
            System.out.println("权限校验");
            //ProceedingJoinPoint  获取目标对象信息的一个对象
            //环绕增强执行目标方法，但是方法可能有返回值，所以我们必须在这里返回
            proceed = joinPoint.proceed();
            System.out.println("日志记录");
        } catch (Throwable throwable) {
            throwable.printStackTrace();
            System.out.println("异常处理");
        } finally {
            System.out.println("释放资源");
        }
        return proceed;
    }

}